package com.ndm.activity;

import com.ndm.common.Const;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PDFViewerActivity extends BasicActivity {

	public WebView WV;
	public String link_url="http://gundals.cafe24.com/java_setting_init_ver1.pdf";
	public static final int MAX_PROGRESS = 40;
	public ProgressDialog mProgressDialog;
	public Handler mProgressHandler;
	int mProgress = 0;
	
	public final int DIALOG_PROGRESS = 0;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pdf_viewer);
        
        WV = (WebView) findViewById(R.id.webview);
        WV.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
		WV.getSettings().setJavaScriptEnabled(true);
        
		WV.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				WV.loadUrl(url);
				return super.shouldOverrideUrlLoading(view, url);
			}
		});
        
        WV.setWebChromeClient(new WebChromeClient() {
		   	   public void onProgressChanged(WebView view, int progress) {
	               mProgress = progress;		// 진행바
		   		   setProgress(progress * 1000);
		   	       super.onProgressChanged(view, progress);
		   	   }
		   	});
		WV.loadUrl(Const.PDF_URL + link_url);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_PROGRESS:
        	 mProgressDialog = new ProgressDialog(PDFViewerActivity.this);
	            mProgressDialog.setTitle("알림창");
	            mProgressDialog.setMessage("페이지를 로딩중입니다.");
	            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	            mProgressDialog.setMax(MAX_PROGRESS);
        	 return mProgressDialog;
        }
        return null;
    }
    
}
